import http from '../http/http'

const register = (data) => {
  return http({
    url: '/register',
    method: 'POST',
    data
  })
}

const login = (data) => {
  return http({
    url: '/login',
    method: 'POST',
    data
  })
}

// 轮播图
const getSwiper = () => {
  return http({
    url: '/banner',
  })
}
// 根据商品类型获取商品
const getGoodsByType = (data) => {
  return http({
    url: '/typeProducts',
    data,
  })
}
// 商品详情
const getDetail = (data) => {
  return http({
    url: '/productDetail',
    data,
  })
}

// 加入购物车
const addCart = (data) => {
  return http({
    url: '/addShopcart',
    data,
    method: 'POST'
  })
}

// 购物车列表
const getCartList = (data) => {
  return http({
    url: '/findAllShopcart',
    data
  })
}

// 修改购物车数量
const changeCartCount = (data) => {
  return http({
    url: '/modifyShopcartCount',
    data,
    method: 'POST'
  })
}

// 删除购物车（一个或多个）
const deleteCart = (data) => {
  return http({
    url: '/deleteShopcart',
    data,
    method: 'POST'
  })
}

// 分类
const getMenuList = (data) => {
  return http({
    url: '/type',
    data,
  })
}

// 用户信息
const getUser = (data) => {
  return http({
    url: '/findMy',
    data
  })
}

// 个人信息
const getPersionInfo = (data) => {
  return http({
    url: '/findAccountInfo',
    data,
  })
}

// 上传头像背景
const updateAvatar = (data) => {
  return http({
    url: '/updateAvatar',
    data,
    method: 'POST'
  })
}

// 上传用户背景
const updateUserBg = (data) => {
  return http({
    url: '/updateUserBg',
    data,
    method: 'POST'
  })
}

// 修改昵称
const updateNickName = (data) => {
  return http({
    url: '/updateNickName',
    data,
    method: 'POST'
  })
}
// 修改简介
const updateDesc = (data) => {
  return http({
    url: '/updateDesc',
    data,
    method: 'POST'
  })
}

// 收藏
const like = (data) => {
  return http({
    url: '/like',
    data,
    method: 'POST'
  })
}

// 取消收藏
const noLike = (data) => {
  return http({
    url: '/notlike',
    data,
    method: 'POST'
  })
}

// 查询商品是否收藏
const findLike = (data) => {
  return http({
    url: '/findlike',
    data
  })
}

// 查询全部收藏的商品
const findAllLike = (data) => {
  return http({
    url: '/findAllLike',
    data
  })
}

// 退出登录
const logout = (data) => {
  return http({
    url: '/logout',
    data,
    method: 'POST'
  })
}

// 添加地址
const addAddress = (data) => {
  return http({
    url: '/addAddress',
    data,
    method: 'POST'
  })
}

// 删除地址
const deleteAddress = (data) => {
  return http({
    url: '/deleteAddress',
    data,
    method: 'POST'
  })
}

// 编辑地址
const editAddress = (data) => {
  return http({
    url: '/editAddress',
    data,
    method: 'POST'
  })
}

// 地址回显
const findAddressByAid = (data) => {
  return http({
    url: '/findAddressByAid',
    data
  })
}

// 地址列表
const getAddressList = (data) => {
  return http({
    url: '/findAddress',
    data
  })
}

// 提交订单页面查询需要购买商品接口
const commitShopcart = (data) => {
  return http({
    url: '/commitShopcart',
    data,
  })
}

// 订单结算
const pay = (data) => {
  return http({
    url: '/pay',
    data,
    method: 'POST'
  })
}

// 查询订单
const findOrder = (data) => {
  return http({
    url: '/findOrder',
    data
  })
}

// 确认收货
const receive = (data) => {
  return http({
    url: '/receive',
    data,
    method: 'POST'
  })
}

// 删除订单
const removeOrder = (data) => {
  return http({
    url: '/removeOrder',
    data,
    method: 'POST'
  })
}

// 修改密码
const updatePassword = (data) => {
  return http({
    url: '/updatePassword',
    data,
    method: 'POST'
  })
}

// 注销账号
const destroyAccount = (data) => {
  return http({
    url: '/destroyAccount',
    data,
    method: 'POST'
  })
}

// 搜索商品
const search = (data) => {
  return http({
    url: '/search',
    data
  })
}

// 邮箱验证码
const emailValidCode = (data) => {
  return http({
    url: '/emailValidCode',
    data,
    method: 'POST'
  })
}

// 验证码验证
const checkValidCode = (data) => {
  return http({
    url: '/checkValidCode',
    data,
    method: 'POST'
  })
}

// 找回密码
const retrievePassword = (data) => {
  return http({
    url: '/retrievePassword',
    data,
    method: 'POST'
  })
}

export default {
  register,
  login,
  getSwiper,
  getGoodsByType,
  getDetail,
  addCart,
  getCartList,
  changeCartCount,
  deleteCart,
  getMenuList,
  getUser,
  getPersionInfo,
  updateAvatar,
  updateUserBg,
  updateNickName,
  updateDesc,
  like,
  noLike,
  findLike,
  findAllLike,
  logout,
  addAddress,
  deleteAddress,
  editAddress,
  findAddressByAid,
  getAddressList,
  commitShopcart,
  pay,
  findOrder,
  receive,
  removeOrder,
  updatePassword,
  destroyAccount,
  search,
  emailValidCode,
  checkValidCode,
  retrievePassword
}